// ************************* 78 character ruler *****************************
// UsbDioControl.h -- NIDAQmx USB DIO control definitions
//
// $Author: Liu Rongwu $
// $Header: /RFBB/Resource/UsbDioControl.h 2     Liu Rongwu $
//
// (c) 2008 Nokia Siemens Networks.
// ************************* 78 character ruler *****************************
#ifndef __USB_DIO_INCL__
#define __USB_DIO_INCL__

#include "cvixml.h"
#include <formatio.h>
#include <ansi_c.h>
#include <NIDAQmx.h>

// Defititions
#define MAX_TASKS 24

/////////////////////////////////////////////////////////////////////////////
// Macro definitions
/////////////////////////////////////////////////////////////////////////////
#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }
#define DAQ_TASK_CLEANUP(hTask) { if(hTask) { DAQmxStopTask(hTask); DAQmxClearTask(hTask); hTask=0; } }
#define XML_DISCARD_ELEMENT(hElement)  if(hElement != 0) { CVIXMLDiscardElement(hElement); hElement = 0; }
#define XML_DISCARD_ATTRIBUTE(hAttrib)  if(hAttrib != 0) { CVIXMLDiscardAttribute(hAttrib); hAttrib = 0; }
#define XML_DISCARD_DOCUMENT(hDocument)  if(hDocument != 0) { CVIXMLDiscardDocument(hDocument); hDocument = 0; }
#define XML_ERR_CHECK(functionCall) { if( (aXmlStatus=functionCall) != 0) { CVIXMLGetErrorString(aXmlStatus, errMsg, sizeof(errMsg)); goto Error; } }

/////////////////////////////////////////////////////////////////////////////
// Type definitions
/////////////////////////////////////////////////////////////////////////////
typedef enum {
   IO_LINE_IN, IO_LINE_OUT, IO_BYTE_IN, IO_BYTE_OUT
} IO_TYPE;

typedef struct {
   TaskHandle m_hTask;  // niDAQmx task handle
   IO_TYPE m_eType;     // I/O port type BYTE / LINE
} SSU_IO_TASK;

// Global variables
//------------------------------------------------------------------------
/*TaskHandle g_hTaskPIPE1_2 = 0; // Port0,line0: RFSW1,3,5,7	(DO)
TaskHandle g_hTaskPIPE3 = 0; // Port0,line1: RFSW2,4,6,8	(DO)
TaskHandle g_hTaskMAIN_DIV = 0; // Port0,line2: RFSW9			(DO)
TaskHandle g_hTaskFixtOpen = 0; // Port0,line3: DCSW1 - Fixture Open (DO)
TaskHandle g_hTaskFiberOptic = 0; // Port0,line4: DCSW2 - FiberOptic Engage/DisEngage (DO)
TaskHandle g_hTaskFixtRdyIN = 0; // Port1,line0: Fixture Ready Signal (DI)
TaskHandle g_hTaskBscanOn = 0; // Port1,line4: BSCAN_ON		(DO)
TaskHandle g_hTaskFlashMode = 0; // Port1,line5: FLASH_MODE		(DO)
TaskHandle g_hTaskSWDLOn = 0; // Port1,line6: SWDL_ON		(DO)
TaskHandle g_hTaskPA3TempPWM = 0; // Port2,line0: TR3_PA_TEMP_PWM	(DO)
TaskHandle g_hTaskPA3EnIN = 0; // Port2,line1: TR3_PA_EN			(DI)
TaskHandle g_hTaskPA2TempPWM = 0; // Port2,line2: TR2_PA_TEMP_PWM	(DO)
TaskHandle g_hTaskPA2EnIN = 0; // Port2,line3: TR2_PA_EN			(DI)
TaskHandle g_hTaskPA1TempPWM = 0; // Port2,line4: TR1_PA_TEMP_PWM	(DO)
TaskHandle g_hTaskPA1EnIN = 0; // Port2,line5: TR1_PA_EN			(DI)
TaskHandle gTaskAFCLK_CounterIN = 0; // Port?,line?: AF_REF_CLK_DIV		(DI/CTR)
*/
/////////////////////////////////////////////////////////////////////////////
// Function prototypes
/////////////////////////////////////////////////////////////////////////////
int InitUsbDio( const char* pszDeviceName );
void CleanupUsbDio( void );


int __declspec(dllexport) TX_TEST InitialiseDio(tTestData *testData, 
                                                   tTestError *testError);
void __declspec(dllexport) TX_TEST CleanupDio(tTestData *testData, 
                                                   tTestError *testError);
int __declspec(dllexport) ReadFixtureReady( void );
int __declspec(dllexport) OpenFixture( void );


#endif // __USB_DIO_INCL__
// ************************* 78 character ruler *****************************
//                            End of header file
// **************************************************************************
